package study.cdc.debezium.support.utils;

import cn.hutool.core.util.StrUtil;
import io.debezium.data.Envelope;
import lombok.Data;

import java.io.Serializable;

@Data
public class Payload<T> implements Serializable {

    private T before;
    private T after;

    private Long ts_ms;
    private String op;
    private Source source;

    @Data
    public class Source implements Serializable {
        private String file;
        private Long pos;
        private Long row;
    }

    public String operation() {
        String opName = "";
        if (StrUtil.isNotBlank(op)) {
            opName = Envelope.Operation.forCode(op)
                    .name();
        }
        return opName;
    }
}
